package cn.javacart.jfinal.php.render;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

public class PhpEnvKit {

	
	private static PhpEnvPool envPool = null;
	
	static void init(boolean devMode, String basePath, int maxActive, int maxIdle, long maxWait){
		GenericObjectPoolConfig config = new GenericObjectPoolConfig();
		{
			config.setMaxTotal(maxActive);
			config.setMaxIdle(maxIdle);
			config.setMaxWaitMillis(maxWait);
		}		
		 envPool = new PhpEnvPool(new PhpEnvFactory(devMode,basePath),config);	
	}
	
	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	public static PhpEnvironment getPhpEnv() throws Exception{
		return envPool.borrowObject();
	}
	
	/**
	 * 释放对象
	 * @param phpEnv
	 */
	public static void release(PhpEnvironment phpEnv){
		envPool.returnObject(phpEnv);
	}
	
}
